package com.rongchuan.wt.controller;


import com.rongchuan.wt.annotation.OperationLog;
import com.rongchuan.wt.entity.EmployeeDTO;
import com.rongchuan.wt.entity.EmployeePageQueryDTO;
import com.rongchuan.wt.result.PageResult;
import com.rongchuan.wt.result.Result;
import com.rongchuan.wt.service.IEmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/employee")
@Api(tags ="员工管理模块接口")
public class EmployeeController {

    @Autowired
    private IEmployeeService employeeService;

    @PostMapping("/add")
    @ApiOperation("添加员工")
    @OperationLog("添加员工")
    public Result<String> add(@RequestBody EmployeeDTO employeeDTO){
        employeeService.addEmployee(employeeDTO);
        return Result.success();
    }

    /**
     * 逻辑删除修改状态
     * 删除部门信息
     */
    @DeleteMapping("/delete")
    @ApiOperation("删除人员信息")
    @OperationLog("删除员工")
    public Result<String> deleteById(Long id){
        employeeService.deleteEmployee(id);
        return Result.success();
    }

    /**
     * 员工分页查询
     */
    @GetMapping("/page")
    @ApiOperation("分页查询员工信息")
    public Result<PageResult> page(EmployeePageQueryDTO employeePageQueryDTO){
        PageResult pageResult = employeeService.pageQuery(employeePageQueryDTO);
        return Result.success(pageResult);
    }
    /**
     * 员工信息导出
     * @param response
     */
    @GetMapping("/export")
    @ApiOperation("导出员工信息数据表")
    public void export(HttpServletResponse response){
        employeeService.exportBusinessData(response);
    }

}
